Skip to content

Add Copy markdown to copy citation #13387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

tushar-2320
Copy link

@tushar-2320 tushar-2320 commented Jun 21, 2025

Closes #12552
This pr contains the changes by adding the Markdown citation copy in the preview panel.I have added changes StandardAction.java ,RightClickMenu.java,CitationStyleOutputFormat.java,ClipboardContentGenerator.java by adding Markdown format and their style respectively.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@tushar-2320
Copy link
Author

hey ,can you just guide If I am in the right direction or not.

@calixtus calixtus marked this pull request as draft June 21, 2025 14:02
@calixtus
Copy link
Member

You could start by fixing your PR description.

@tushar-2320
Copy link
Author

I have made the changes but not able find the fault as I can't see the effect in ui
can anyone review and guide me through this.

@koppor
Copy link
Member

koppor commented Jun 22, 2025

I have made the changes but not able find the fault as I can't see the effect in ui

  • fault of the test? -> Ignore that one (its an online download thing and the server is unreliable)
  • GUI effect -> you should be able to see your changes.

can anyone review and guide me through this.

Please add a CHANGELOG.md entry.

@koppor
Copy link
Member

koppor commented Jun 22, 2025

Tried out, UI works...

image

Update The content is a bit strange. I checked the code - it seems, citeproc.java is not used correctly?

\[1\]L\. Wegmeth\, T\. Vente\, and J\. Beel\, “Recommender Systems Algorithm Selection for Ranking Prediction on Implicit Feedback Datasets\,” in *Proceedings of the 18th ACM Conference on Recommender Systems*\, in RecSys ’24\. New York\, NY\, USA\: Association for Computing Machinery\, Oct\. 2024\, pp\. 1163–1167\. doi\: 10\.1145\/3640457\.3691718\.<br />

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a deeper look, I did not see any wiring in the library https://github.com/michel-kraemer/citeproc-java. Please do so.

@@ -5,7 +5,8 @@
public enum CitationStyleOutputFormat {

HTML("html", OS.NEWLINE + "<br>" + OS.NEWLINE),
TEXT("text", "");
TEXT("text", ""),
MARKDOWN("markdown", OS.NEWLINE + "<br>" + OS.NEWLINE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<br> is not a good line separator in markdown. Just remove it. Two empty lines are ok.

@@ -120,6 +121,13 @@ static ClipboardContent processHtml(List<String> citations) {
return content;
}

static ClipboardContent processMarkdown(List<String> citations) {
String result = String.join(CitationStyleOutputFormat.MARKDOWN.getLineSeparator(), citations);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the convertion to Markdown made?

I think, you need to deal with setOutputFormat somehow michel-kraemer/citeproc-java@66cad6b

@tushar-2320 tushar-2320 requested a review from koppor June 24, 2025 12:08
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test so that one "sees" a conversion result in the code.

Comment on lines +125 to +128
/**
* Insert each citation into HTML.
* convert HTML to markdown using flexmark.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is trivial and simply restates what the code does without providing additional information about the reasoning or important details about the implementation.

@calixtus calixtus changed the title Draft:fix:Added copy Markdown to copy citation #12552. Add Copy markdown to copy citation Jun 27, 2025
@jabref-machine
Copy link
Collaborator

JUnit tests of jablib are failing. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Tests / Unit tests (pull_request)" and click on it.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

@tushar-2320 tushar-2320 marked this pull request as ready for review July 19, 2025 04:33
* convert HTML to markdown using flexmark.
*/
@VisibleForTesting
static ClipboardContent processMarkdown(List<String> citations) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method uses string concatenation for multiline HTML template instead of Java text blocks ("""). This makes the code less readable and maintainable.

@tushar-2320 tushar-2320 force-pushed the fix-for-issue-12552 branch from 0c2907f to b3eb93c Compare July 19, 2025 06:29
@tushar-2320 tushar-2320 requested a review from koppor July 19, 2025 06:52
String actual = markdown.getString();

// Print actual output for debugging
System.out.println("=== Actual Markdown Output ===");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for these, on failure assertEquals will show the diff

Siedlerchr
Siedlerchr previously approved these changes Jul 19, 2025
@koppor koppor added the status: awaiting-second-review For non-trivial changes label Jul 20, 2025
Comment on lines 162 to 164
// Normalize both strings to ignore whitespace and formatting issues
String normalizedActual = actual.replaceAll("\\s+", " ").trim();
String normalizedExpected = expected.replaceAll("\\s+", " ").trim();
Copy link
Member

@subhramit subhramit Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are "formatting issues" here specifically?
Given we know the expected string, can we trace where the extra whitespaces might come from in the actual?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually you are right I think I was getting cautious that is why I was removing whitespaces.
but I understood that it overall fails the point of testing.

subhramit
subhramit previously approved these changes Jul 21, 2025
@subhramit subhramit removed the status: awaiting-second-review For non-trivial changes label Jul 21, 2025
@tushar-2320 tushar-2320 requested a review from Siedlerchr July 21, 2025 09:34
Copy link

trag-bot bot commented Jul 23, 2025

@trag-bot didn't find any issues in the code! ✅✨

* convert HTML to markdown using flexmark.
*/
@VisibleForTesting
static ClipboardContent processMarkdown(List<String> citations) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You followed @Siedlerchr's recommendation and did not follow mine to use citeproc-java conversion. (michel-kraemer/citeproc-java@66cad6b)

There needs to be AT LEAST a comment, why citeproc-java could not be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unaware of this, good point

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe my comment here #13387 (comment) is of help? Just to try out how to route things to that plugin?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it works for all previews! Not just csl. I see no advantage in using citeproc here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only point is that find citeproc more configurable than flexmark.
flexmark do that only in one line.
in citeproc I think we have to write a function to do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do case handling

If CSL use citeproc (specialized!, e.g. DOI linked)

If no CSL, use flexmark

@subhramit subhramit dismissed their stale review July 23, 2025 22:19

Discussion/changes pending

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add markdown as copy format
7 participants